package cn.edu.neusoft.wuguangsheng.market.activity;

import android.content.SharedPreferences;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.market.R;
import cn.edu.neusoft.wuguangsheng.market.adapter.OrderInfoAdapter;
import cn.edu.neusoft.wuguangsheng.market.bean.OrderFoodInfo;
import cn.edu.neusoft.wuguangsheng.market.listener.ListListener;
import cn.edu.neusoft.wuguangsheng.market.model.OrderFoodInfoModel;

public class OrderFoodsActivity extends BaseActivity {
    String orid,mrid;
    RecyclerView recycleorder;
    private List<OrderFoodInfo> items;
    ImageView orfh;
    Boolean up=false;
    @Override
    void initView() {
        setLayout_file(R.layout.activity_order_foods);
        orid = getIntent().getStringExtra("orid");
        mrid=getIntent().getStringExtra("mrid");


        SharedPreferences.Editor editor= getSharedPreferences("userInfo",MODE_PRIVATE).edit();
        editor.putString("mrid",mrid);
        editor.commit();

    //Toast.makeText(OrderFoodsActivity.this,mrid,Toast.LENGTH_SHORT).show();
        recycleorder=(RecyclerView)findViewById(R.id.recycleorderinfo);
        orfh=(ImageView)findViewById(R.id.orfh);

        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(OrderFoodsActivity.this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recycleorder.setLayoutManager(linearLayoutManager);

    }

    @Override
    void initEvent() {
orfh.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        finish();
    }
});
    }

    @Override
    void initDate() {
        OrderFoodInfoModel orderFoodInfoModel=new OrderFoodInfoModel();
        orderFoodInfoModel.showFoodInfo(orid,listListener);
    }
    ListListener<OrderFoodInfo> listListener=new ListListener<OrderFoodInfo>() {
        @Override
        public void onResponse(List<OrderFoodInfo> list) {
            items=list;
            OrderInfoAdapter orderInfoAdapter=new OrderInfoAdapter(OrderFoodsActivity.this,items,R.layout.commentcard);
            recycleorder.setAdapter(orderInfoAdapter);
            recycleorder.setItemAnimator(new DefaultItemAnimator());
        }

        @Override
        public void onFail(String msg) {

        }
    };


//    @Override
//    public void onPause() {
//        super.onPause();
//        up=true;
//
//    }
//
//    @Override
//    public void onResume() {
//        super.onResume();
//        if(up){
//            initView();
//            up=false;
//        }
//    }
}
